<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>TAGP向量团队协作成长平台</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/css.css">

</head>

<body>

 <div class="searchBar">

   <form id="form" class="navbar-form navbar-left" role="search" action="topic/list" method="post">
          <div class="input-group title" >
          基础项管理
          </div>
        <div class="form-group">
		<div class="input-group">
          <div class="input-group-addon">搜索</div>
          <input class="form-control" style="width:100px" name="form.keywords" value="${form.keywords}">
       </div>
		<div class="input-group">
          <div class="input-group-addon">时间段</div>
          <input class="form-control" style="width:100px" name="form.startTime" value="${form.startTime}">
       </div>
        </div>
        <a href="javascript:search()"  class="btn btn-default btn-sm"><span class="glyphicon"></span>查询</a>
        <a href="javascript:exportBtn()"   class="btn btn-default  btn-sm"   ><span class="glyphicon glyphicon-eject"></span> 导出</a>
 
      </form>

      <div  class="navbar-right">
       <button id="addBtn" type="button"  class="btn btn-primary navbar-btn btn-sm"   ><span class="glyphicon glyphicon-plus"></span> 添加</button>
       <button id="addExcelBtn" type="button"  class="btn btn-primary navbar-btn btn-sm"   ><span class="glyphicon glyphicon-plus"></span> 导入Excel</button>
      </div>
</div>

<table class="table table-striped table-hover table-bordered">
   <tr>
	<td style="width:14%">序号</td>
	<td style="width:14%">主题名称</td>
	<td style="width:14%">主题简介</td>
	<td style="width:14%">章节数</td>
	<td style="width:14%">创建者</td>
	<td style="width:14%">创建时间</td>
    <td style="width:14%">操作</td>
   </tr>
  <c:forEach items="${topics}" var="topic" varStatus="index"> 
    <tr id="tr${topic.id}">
    <td>${index.index+1}</td> 
     <td>${topic.name}</td>
     <td>${topic.content}</td>
     <td>${topic.chapterCount}</td>
     <td>${topic.userId}</td>
     <td>${topic.createTime}</td>
    <td><button  data="${topic.id}" class="btn btn-success  btn-sm editBtn" ><span class="glyphicon glyphicon-pencil"></span> 修改</button> <button data="${topic.id}" class="btn btn-success  btn-sm delBtn"><span class="glyphicon glyphicon-remove"></span> 删除</button></td>
   </tr>
  </c:forEach>
  </table>
<div class="pull-right" style="margin-right:10px">
<ul class="pagination" id="pagination"  formId="form2"  id="pager" currentpage="${pager.currentPage}"   pageTotal="${pager.pageTotal}"></ul>
<form action="topic/list" id="form2" name="form2" method="post">
<input type="hidden"  id="currentPage"   name="pager.currentPage"   value="${pager.currentPage}">
<input type="hidden" name="form.keywords" value="${form.keywords}">
<input type="hidden" name="form.startTime" value="${form.startTime}">
</form>
</div>

 <script src="assets/js/jquery-1.11.1.min.js"></script>
 <script src="assets/js/bootstrap.min.js"></script>
 <script src="assets/js/js.js"></script>
 <script type="text/javascript">
 function exportBtn(){
     $("#form").attr("action","topic/export");
	 $("#form").submit();
 }
 function search(){
     $("#form").attr("action","topic/list");
     $("#form").submit();
 }
 $(function(){
 	$("button.editBtn").click(function(){
 		var id=$(this).attr("data");
 		KXBASE.fn.baseWin(0,"修改信息","topic/initModify?id="+id,800,350,{operateBtn:'修改',closeBtn:'关闭'},function(){
       	  $("#commonActionIframe")[0].contentWindow.submitForm();
      });
 	})
 	$("#addBtn").click(function(){
 		KXBASE.fn.baseWin(0,"添加信息","topic/initAdd",800,350,{operateBtn:'添加',closeBtn:'关闭'},function(){
       	  $("#commonActionIframe")[0].contentWindow.submitForm();
      });
 	})
 	$("#addExcelBtn").click(function(){
 		KXBASE.fn.baseWin(0,"批量导入","topic/addTopicByEXCEL.jsp",800,350,{operateBtn:'添加',closeBtn:'关闭'},function(){
       	  $("#commonActionIframe")[0].contentWindow.submitForm();
      });
 	})
 	$("button.delBtn").click(function(){
 		var id=$(this).attr("data");
 		 if (confirm("是否确认删除该项？")) {
 			$.ajax({type:"post",dataType:"json",url:"topic/del",data:"id="+id,success:function(result){
			if(result.success){
 			   $("#tr"+id).remove();
			}else{
				if(result.msg){
					alert(msg);
				}else{
					alert("操作失败");
				}
			}
 			}})
 		 }
 	})
 })
 </script>
</body>
</html>
